package com.kingland.neusoft.course.controller;

import com.kingland.neusoft.course.mapper.dao.BorrowList;
import com.kingland.neusoft.course.mapper.dao.BorrowModel;
import com.kingland.neusoft.course.service.BorrowService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class BorrowController {
    private final BorrowService borrowService;
    public BorrowController(BorrowService borrowService) {
        this.borrowService = borrowService;
    }

    @PostMapping("/borrows")
    public void addBorrowInfo(@RequestBody BorrowModel borrowModel){
        borrowService.BorrowBook(borrowModel);
    }

    @DeleteMapping("/borrows/{infoId}")
    public void ReturnBook(@PathVariable("infoId") Long BorrowUserId){
        borrowService.ReturnBook(BorrowUserId);
    }

    @GetMapping("/borrows/{userId}")
    public List<BorrowList> getAllBorrowBook(@PathVariable("userId") Long borrowUserId){
        return borrowService.GetAllBorrowBook(borrowUserId);
    }

    @GetMapping("/borrows/count")
    public Map<String, Integer> countUser() {
        Integer userCount = borrowService.count();
        return Map.of("count", userCount);
    }
}
